package cn.hoichun.news.Domain;

import java.util.List;

/**
 * @author Hoichun
 */
public class Page<T> {
    private List<T> list;
    private int pageNum;
    private int pageSize;

    public Page(List<T> list, int pageNum, int pageSize) {
        this.list = list;
        this.pageNum = pageNum;
        this.pageSize = pageSize;
    }

    public Page(List<T> list) {
        this.list = list;
        this.pageNum = 1;
        this.pageSize = list.size();
    }

    public List<T> getList() {
        this.pageNum= Math.max(pageNum, 1);
        return list.subList((pageNum - 1) * pageSize, Math.min(pageNum * pageSize, list.size()));
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalPages() {
        return list.size() / pageSize + 1;
    }

    public int getTotalSize() {
        return list.size();
    }
}
